package com.geostar.constructionland.analyse.service.fxrzstatistic.impl;

import com.geostar.constructionland.analyse.mapper.FxrzStasticMapper;
import com.geostar.constructionland.analyse.service.fxrzstatistic.FxrzStatisticService;
import com.geostar.constructionland.common.entity.analyse.FxrzStatisticPage;
import com.geostar.constructionland.common.entity.analyse.FxrzStatistics;
import com.geostar.constructionland.common.entity.response.ExtJsAjaxResponse;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * @author chengan
 * @description 分析日志统计Service层级
 */
@Service
public class FxrzStatisticServiceImpl implements FxrzStatisticService {

    @Autowired
    FxrzStasticMapper fxrzStasticMapper;

    @Override
    public ExtJsAjaxResponse getFxrzStatisticList(int pageNo, int pageNum, String ywid) {
        ExtJsAjaxResponse extJsAjaxResponse ;
        if(StringUtils.isEmpty(ywid)){
            //走全部分页查询
            int initRow = (pageNo - 1) * pageNum;
            int endRow = pageNo * pageNum;
            //查业务Id
            List<String> ywids = fxrzStasticMapper.getYwid(initRow, endRow);
            //查总页数
            Integer fxrzStatisticsCount = fxrzStasticMapper.getFxrzStatisticsCount();
            //拿到例表数据
            List<FxrzStatistics> fxrzStatistics = fxrzStasticMapper.getFxrzStatistics(ywids);
            FxrzStatisticPage page = new FxrzStatisticPage();
            page.setTotal(fxrzStatisticsCount);
            page.setRecords(fxrzStatistics);
            extJsAjaxResponse = ExtJsAjaxResponse.createBySuccess(page);
        }else{
            //把ywid拿出来单独做查询
            List<String> ywids = new LinkedList<>();
            ywids.add(ywid);
            List<FxrzStatistics> fxrzStatistics = fxrzStasticMapper.getFxrzStatistics(ywids);
            FxrzStatisticPage page = new FxrzStatisticPage();
            //总页数设为1
            page.setTotal(1);
            page.setRecords(fxrzStatistics);
            extJsAjaxResponse = ExtJsAjaxResponse.createBySuccess(page);
        }
        return  extJsAjaxResponse;
    }
}
